package com.isp.common.model.vo;


import com.alibaba.excel.util.StringUtils;

/**
 * 通知实体
 *
 * @author Linsy
 * @created 2023/10/17
 */
public class Notification {
    /**
     * 开始时间
     */
    private final String startTime;
    /**
     * 结束时间
     */
    private final String endTime;
    /**
     * 异常时间
     */
    private final String time;
    /**
     * 机器地址
     */
    private final String host;
    /**
     * 请求类
     */
    private final String clazz;
    /**
     * 请求方法
     */
    private final String method;
    /**
     * 用户信息
     */
    private final String userInfo;
    /**
     * 请求参数
     */
    private final String request;
    /**
     * 请求url
     */
    private final String apiUrl;
    /**
     * 响应体
     */
    private final String response;
    /**
     * 异常信息
     */
    private final String exceptionMessage;

    private Notification(NotificationBuilder builder) {
        this.startTime = builder.startTime;
        this.endTime = builder.endTime;
        this.time = builder.time;
        this.host = builder.host;
        this.clazz = builder.clazz;
        this.method = builder.method;
        this.request = builder.request;
        this.userInfo = builder.userInfo;
        this.apiUrl = builder.apiUrl;
        this.response = builder.response;
        this.exceptionMessage = builder.exceptionMessage;
    }

    public static class NotificationBuilder {
        private String startTime;
        private String endTime;
        private String time;
        public String host;
        private String clazz;
        private String method;
        private String request;
        private String userInfo;
        private String apiUrl;
        private String response;
        private String exceptionMessage;

        public NotificationBuilder() {
        }

        public NotificationBuilder(String startTime, String endTime) {
            this.startTime = startTime;
            this.endTime = endTime;
        }

        public NotificationBuilder time(String time) {
            this.time = time;
            return this;
        }

        public NotificationBuilder host(String host) {
            this.host = host;
            return this;
        }

        public NotificationBuilder clazz(String clazz) {
            this.clazz = clazz;
            return this;
        }

        public NotificationBuilder method(String method) {
            this.method = method;
            return this;
        }

        public NotificationBuilder request(String requestParams) {
            this.request = requestParams;
            return this;
        }

        public NotificationBuilder userInfo(String userInfo) {
            this.userInfo = userInfo;
            return this;
        }

        public NotificationBuilder apiUrl(String apiUrl) {
            this.apiUrl = apiUrl;
            return this;
        }

        public NotificationBuilder response(String response) {
            this.response = response;
            return this;
        }

        public NotificationBuilder exceptionMessage(String exceptionMessage) {
            this.exceptionMessage = exceptionMessage;
            return this;
        }

        public Notification build() {
            return new Notification(this);
        }
    }

    @Override
    public String toString() {
        StringBuilder logInfo = new StringBuilder();
        if (StringUtils.isNotBlank(startTime)) {
            logInfo.append("开始时间：").append(startTime).append("\n");
        }
        if (StringUtils.isNotBlank(endTime)) {
            logInfo.append("结束时间：").append(endTime).append("\n");
        }
        if (StringUtils.isNotBlank(time)) {
            logInfo.append("操作时间：").append(time).append("\n");
        }
        if (StringUtils.isNotBlank(host)) {
            logInfo.append("节点IP：").append(host).append("\n");
        }
        if (StringUtils.isNotBlank(clazz)) {
            logInfo.append("请 求 类：").append(clazz).append("\n");
        }
        if (StringUtils.isNotBlank(method)) {
            logInfo.append("请求方法: ").append(method).append("\n");
        }
        if (StringUtils.isNotBlank(apiUrl)) {
            logInfo.append("请求接口：").append(apiUrl).append("\n");
        }
        if (StringUtils.isNotBlank(request)) {
            logInfo.append("请求参数：").append(request).append("\n");
        }
        if (StringUtils.isNotBlank(userInfo)) {
            logInfo.append("用户信息：").append(userInfo).append("\n");
        }
        if (StringUtils.isNotBlank(response)) {
            logInfo.append("响应参数：").append(response).append("\n");
        }
        if (StringUtils.isNotBlank(exceptionMessage)) {
            logInfo.append("异常信息：").append(exceptionMessage).append("\n");
        }
        return logInfo.toString();
    }
}
